import {defineStore} from 'pinia'
import {ref} from 'vue'
import myAxios from "@/axios/axios.js";

export const useLoginUserStore = defineStore('loginUser', () => {
    const loginUser = ref({
        id:'',
        userName: '未登录',
        avatarUrl:'',
        email:'',
        phone:'',
    })

    /**
     * 获取登录用户信息
     */
    async function fetchLoginUser() {
        const res = await myAxios.get('/user/getLoginUser');
        console.log(res)
        if (res.code === 0 && res.data) {
            loginUser.value = res.data
        }
    }

    function setLoginUser(newLoginUser) {
        loginUser.value = newLoginUser
    }

    return { loginUser, setLoginUser, fetchLoginUser }
})
